<template>
  <div>
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">
              本周上线情况
            </div>
            <div class="card-panel-num">总次数 10</div>

            <div class="card-panel-num">异常数 10</div>

            <div class="card-panel-num">更新率 15%</div>
            <div class="card-panel-num">平均耗时 60m</div>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6">
        <div class="card-panel">

          <div class="card-panel-description">
            <div class="card-panel-text">
              本月上线情况
            </div>

          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6">
        <div class="card-panel">

          <div class="card-panel-description">
            <div class="card-panel-text">
              本年上线情况
            </div>

          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6">
        <div class="card-panel">

          <div class="card-panel-description">
            <div class="card-panel-text">
              服务总数
            </div>

          </div>
        </div>
      </el-col>

    </el-row>
    <div>
      <el-row :gutter="40" class="panel-group">
        <el-col :xs="12" :sm="12" :lg="24">

          <el-date-picker
            v-model="value2"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
          />
        </el-col>
      </el-row>
      <el-row :gutter="40" class="panel-group">
        <el-col :xs="12" :sm="12" :lg="12">
          <div class="card-panel">
            <div class="card-panel-description">
              <div class="card-panel-text">
                更新次数/更新率曲线
              </div>
            </div>
            <v-chart :options="polar" />
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="12">
          <div class="card-panel">
            <div class="card-panel-description">
              <div class="card-panel-text">
                成功率曲线
              </div>

            </div>
            <v-chart :options="polar" />
          </div>
        </el-col>
      </el-row>

      <el-row :gutter="40" class="panel-group">
        <el-col :xs="12" :sm="12" :lg="12">
          <div class="card-panel">
            <div class="card-panel-description">
              <div class="card-panel-text">
                成功率曲线
              </div>

            </div>
            <v-chart :options="polar" />
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="12">
          <div class="card-panel">
            <div class="card-panel-description">
              <div class="card-panel-text">
                平均耗时
              </div>

            </div>
            <v-chart :options="polar" />
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="40" class="panel-group">
        <el-col :xs="12" :sm="12" :lg="8">
          <div class="card-panel">
            <div class="card-panel-description">
              <div class="card-panel-text">
                耗时TOP5
              </div>

            </div>
            <el-table
              :data="tableData"
              style="width: 100%"
            >
              <el-table-column
                prop="service_name"
                label="服务"
                width="180"
              />
              <el-table-column
                prop="update_time"
                label="耗时（分钟）"
                width="180"
              />
            </el-table>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="8">
          <div class="card-panel">
            <div class="card-panel-description">
              <div class="card-panel-text">
                次数TOP5
              </div>

            </div>
            <el-table
              :data="tableData"
              style="width: 100%"
            >
              <el-table-column
                prop="service_name"
                label="服务"
                width="180"
              />
              <el-table-column
                prop="count"
                label="次数"
                width="180"
              />
            </el-table>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="8">
          <div class="card-panel">
            <div class="card-panel-description">
              <div class="card-panel-text">
                异常TOP5
              </div>

            </div>
            <el-table
              :data="tableData"
              style="width: 100%"
            >
              <el-table-column
                prop="service_name"
                label="服务"
                width="180"
              />
              <el-table-column
                prop="failed"
                label="次数"
                width="180"
              />
            </el-table>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import ECharts from 'vue-echarts'
import 'echarts/lib/chart/line'
import 'echarts/lib/component/polar'
import 'echarts/lib/component/title'
import 'echarts/lib/component/tooltip'
export default {
  components: {
    'v-chart': ECharts
  },
  data() {
    return {
      polar: {
        // title: {
        //   text: '更新次数/更新率曲线'
        // },
        xAxis: {
          type: 'category',
          splitLine: {
            show: false
          },
          data: ['第一周', '第二周', '第三周', '第四周', '第五周', '第六周', '第七周', '第八周', '第九周']

        },
        tooltip: {
          trigger: 'axis'
        },
        yAxis: {
          type: 'value',
          splitLine: {
            show: false
          }
        },
        series: [{
          data: [31, 29, 45, 20, 32, 40, 18, 22, 36],
          type: 'line',
          smooth: true
        }],
        height: 60
      },
      tableData: [{
        service_name: 'Service A',
        update_time: '80m',
        count: 20,
        failed: 6
      }, {
        service_name: 'Service B',
        update_time: '60m',
        count: 18,
        failed: 5
      }, {
        service_name: 'Service C',
        update_time: '50m',
        count: 16,
        failed: 4
      }, {
        service_name: 'Service D',
        update_time: '40m',
        count: 14,
        failed: 2
      }, {
        service_name: 'Service E',
        update_time: '30m',
        count: 10,
        failed: 2
      }],
      pickerOptions: {
        shortcuts: [{
          text: '本月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * Number(end.getDate() - 1))
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '本年度',
          onClick(picker) {
            const end = new Date()
            const start = new Date(end.getFullYear(), 0)
            // start.setTime(start.getTime() - 3600 * 1000 * 24 * Number(end.getDate() - 1))
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近六个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 180)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一年',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      value2: [new Date((new Date()).getFullYear(), 0), new Date()]
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }
  .card-panel {
    height: 188px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 10px;
      margin-left: 10px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        float: right;
        font-size: 20px;
        width: 100%;
        word-wrap: break-word;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
